#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include <QTimer>

MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //点击退出菜单项 实现体退出
    connect(ui->actionQ,&QAction::triggered,[=]()
    {
       this->close();
    });

    this->setFixedSize(330,590);
    this->setWindowTitle("翻金币");
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));


    //创建第二个选关场景
    chooseScene = new ChooseLevelScene;

    //开始按钮
     MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
     startBtn->setParent(this);
     startBtn->move(this->width()*0.5 - startBtn->width()*0.5,this->height()*0.7);

     connect(startBtn,&MyPushButton::clicked,[=](){
         startBtn->zoom1();//向上跳跃
         startBtn->zoom2();//向下跳跃

         //延时操作 500毫秒后
         QTimer::singleShot(500,this,[=]{
                   //进入选择关卡场景  自身隐藏 显示选择关卡场景
                   this->hide();
                   chooseScene->show();
          });
     });
}

//绘图事件
void MainScene::paintEvent(QPaintEvent*)
{
    //创建画家对象
    QPainter painter(this);
    //创建QPixmap对象
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    //绘制背景
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    //加载标题资源
    pix.load(":/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);

}

MainScene::~MainScene()
{
    delete ui;
}

